import { Mongo } from 'meteor/mongo';
import { Factory } from 'meteor/dburles:factory';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';

class StoreBlocks extends Mongo.Collection {
  insert(doc, callback) {
    const ourDoc = doc;
    const result = super.insert(ourDoc, callback);
    return result;
  }
  update(selector, modifier) {
    const result = super.update(selector, modifier);
    return result;
  }
  remove(selector) {
    const result = super.remove(selector);
    return result;
  }
}

export const mycbops = new StoreBlocks('chainblockbuf');

// Deny all client-side updates since we will be using methods to manage this collection
mycbops.deny({
  insert() { return true; },
  update() { return true; },
  remove() { return true; },
});


mycbops.schema = new SimpleSchema({
  blockheight:{
    type: Number,
    min: 0,
  },
  created: {
    type: String,
    max: 100,
    optional: true,
  },
  uuid: {
    type: String,
    optional: true,
  },
  type: {
    type: String,
    min: 0,
    optional: true,
  },
  ccid: {
    type: String,
    max: 1000,
    optional: true,
  },
  payload:{
    type: String,
    optional: true,
  }
});

mycbops.attachSchema(mycbops.schema);




if (Meteor.isServer) {
  // This code only runs on the server
  Meteor.publish('chainblockbuf', function cbPublication() {
    return mycbops.find();
  });
}